package com.qiangesoft.blog.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qiangesoft.blog.system.entity.SysRole;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 系统角色  Mapper 接口
 * </p>
 *
 * @author qiange
 * @since 2023-06-01
 */
public interface SysRoleMapper extends BaseMapper<SysRole> {

    Long queryByUserId(Long userId);

    List<Long> queryByRoleMenu(Long roleId);

    void delByRoleId(@Param("roleId") Long roleId, @Param("menus") List<Long> menus);

    void insertBatchByRole(@Param("menus") List<Long> menus, @Param("roleId") Long roleId);

    @Delete("delete from sys_user_role where user_id=#{userId}")
    void deleteByUserId(Integer userId);

    @Insert("insert into sys_user_role(role_id,user_id) values(#{roleId},#{userId})")
    void insertToUserId(@Param("userId") Long userId, @Param("roleId") Long roleId);

    @Update("update sys_user_role set role_id=#{roleId} where user_id=#{userId}")
    void updateByUserId(@Param("userId") Long userId, @Param("roleId") Long roleId);

    List<String> selectByUserId(Long loginId);
}
